package org.example.hansp.thread.ticket;


public class SellTicketDemo {
    public static void main(String[] args) {
        SellTicket ticket1 = new SellTicket();
        SellTicket ticket2 = new SellTicket();
        SellTicket ticket3 = new SellTicket();
        Thread t1 = new Thread(ticket1);
        Thread t2 = new Thread(ticket2);
        Thread t3 = new Thread(ticket3);
        t1.start();
        t2.start();
        t3.start();
    }
}
class SellTicket extends Thread {
    private static int counter = 100;
    @Override
    public void run() {
            while (true) {
                if(counter<=0){
                    System.out.println("售票结束");
                    break;
                }
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("窗口"+this.currentThread().getName()+"售出一张票"
                +"剩余： "+(--counter)+"张票");
            }
    }
}